###########################################
Replication Materials for "Party Switching in Elected Upper Chambers: The Case of the Brazilian Senate"
###########################################

General Commentary:
In this folder, you'll find the materials to replicate the following study:
Couto, Lucas and Lopes, Amanda Vitória and Albala, Adrián and Paley, Vinícius. "Party Switching in Elected Upper Chambers: The Case of the Brazilian Senate," published in Political Studies Review.

You'll find the following files here:
- "BrSenSwitch.csv": Dataset for party switching in Brazil's upper chamber from 1990 to 2022. The period between 2008-2014 is excluded due to the existence of anti-defection rulings. For more information, please see the fourth section of the main text and the second section of the Supplementary Material. 

- "Codebook.xlsx": Documentation for "BrSenSwitch.csv".

- "Figures_PS.R": R Script to make the figures for the main document.

- "Main_Model_PS.R": R Script to produce the models and marginal effects presented in the main document.

- "Supp_Mat_PS_1.R": R Script to reproduce the second section of the Supplementary Material examining the legal constraints around party switching in the Brazilian Senate. 

- "Supp_Mat_PS_2.R": R Script to reproduce the third section of the Supplementary Material examining the underlying concept captured by W-Nominate. 

- "Supp_Mat_PS_3.R": R Script to reproduce the fourth section of the Supplementary Material plotting the office-related proxies employed in the main document.

- "Supp_Mat_PS_4.R": R script to provide alternative visualisations of the marginal effects presented in the main text.

- "Supp_Mat_PS_5.R": R script to produce the robustness checks for the models reported in the main text. Specifically, this script contains the code necessary (i) to conduct the empirical analysis with an alternate measure of the vote-seeking approach (number of past governorship in senators' states instead of vote share in the Chamber of Deputies in the last election), (ii) to test for the Independence of Irrelevant Alternatives (IIA), (iii) to employ a different modelling strategy (logit), (iv) to test whether the results are robust to a different conceptualisation of party switching.

You should note that we used another dataset to run "Supp_Mat_PS_2.R". However, as the data are not our property, we feel uncomfortable sharing them. Regardless, the script points out where the dataset can be downloaded. The same applies to the fonts used in data visualisations.

In case of any doubt, please feel free to reach out at lucasalmeidacouto040@gmail.com

###########################################
R sessionInfo()

R version 4.3.1 (2023-06-16 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22631)

Matrix products: default


locale:
[1] LC_COLLATE=Portuguese_Brazil.utf8  LC_CTYPE=Portuguese_Brazil.utf8    LC_MONETARY=Portuguese_Brazil.utf8
[4] LC_NUMERIC=C                       LC_TIME=Portuguese_Brazil.utf8    

time zone: Europe/Paris
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] survival_3.5-5         patchwork_1.2.0        mclogit_0.9.6          Matrix_1.6-0           marginaleffects_0.13.0
 [6] lubridate_1.9.2        forcats_1.0.0          stringr_1.5.0          dplyr_1.1.2            purrr_1.0.1           
[11] readr_2.1.4            tidyr_1.3.0            tibble_3.2.1           tidyverse_2.0.0        stargazer_5.2.3       
[16] showtext_0.9-6         showtextdb_3.0         sysfonts_0.8.8         ragg_1.2.5             MetBrewer_0.2.0       
[21] ggalluvial_0.12.5      ggplot2_3.5.1          geofacet_0.2.0        

loaded via a namespace (and not attached):
 [1] tidyselect_1.2.0    TH.data_1.1-2       timechange_0.2.0    estimability_1.4.1  lifecycle_1.0.4     sf_1.0-14          
 [7] magrittr_2.0.3      compiler_4.3.1      rlang_1.1.1         tools_4.3.1         utf8_1.2.3          yaml_2.3.7         
[13] data.table_1.15.4   sp_2.0-0            classInt_0.4-9      imguR_1.0.3         geogrid_0.1.1       abind_1.4-5        
[19] multcomp_1.4-25     KernSmooth_2.23-21  withr_2.5.0         grid_4.3.1          fansi_1.0.4         xtable_1.8-4       
[25] e1071_1.7-13        colorspace_2.1-0    emmeans_1.8.8       scales_1.3.0        MASS_7.3-60         cli_3.6.1          
[31] mvtnorm_1.2-2       generics_0.1.3      rstudioapi_0.14     httr_1.4.6          tzdb_0.4.0          DBI_1.1.3          
[37] proxy_0.4-27        splines_4.3.1       rnaturalearth_0.3.3 vctrs_0.6.3         sandwich_3.0-2      jsonlite_1.8.5     
[43] carData_3.0-5       car_3.1-2           hms_1.1.3           ggrepel_0.9.3       systemfonts_1.0.4   jpeg_0.1-10        
[49] units_0.8-2         glue_1.6.2          codetools_0.2-19    stringi_1.7.12      gtable_0.3.3        munsell_0.5.0      
[55] pillar_1.9.0        R6_2.5.1            memisc_0.99.31.6    textshaping_0.3.6   lattice_0.21-8      png_0.1-8          
[61] class_7.3-22        Rcpp_1.0.10         coda_0.19-4         gridExtra_2.3       zoo_1.8-12          rgeos_0.6-3        
[67] pkgconfig_2.0.3    